package tree;

import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;

public class DatabaseTreeCellRenderer extends DefaultTreeCellRenderer {
	private String rootPath = "/frame/icon/server.PNG";
	private String catalogPath = "/frame/icon/database.PNG";
	private String tablePath = "/frame/icon/table.PNG";
	private String fieldPath = "/frame/icon/field_large.PNG";
	private ImageIcon rootIcon = null;
	private ImageIcon catalogIcon = null;
	private ImageIcon tableIcon = null;
	private ImageIcon fieldIcon = null;

	public DatabaseTreeCellRenderer() {
		Class tc = this.getClass();
		rootIcon = new ImageIcon(tc.getResource(rootPath));
		catalogIcon = new ImageIcon(tc.getResource(catalogPath));
		tableIcon = new ImageIcon(tc.getResource(tablePath));
		fieldIcon = new ImageIcon(tc.getResource(fieldPath));
	}

	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
		super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
		ImageIcon icon = null;
		AbstractTreeNode node = (AbstractTreeNode) value;
		switch (node.getNodeType()) {
		case AbstractTreeNode.RootNode:
			icon = this.rootIcon;
			break;
		case AbstractTreeNode.CatalogNode:
			icon = this.catalogIcon;
			break;
		case AbstractTreeNode.TableNode:
			icon = this.tableIcon;
			break;
		case AbstractTreeNode.FieldNode:
			icon = this.fieldIcon;
			break;
		default:
			System.out.println("TreeRenderer�������:�����node����");
			break;
		}
		this.setIcon(icon);
		return this;
	}
}
